package today.belief.mole.api;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * @Author LXH
 * @Date 2022/6/30
 * @Description 分页对象
 */
@Getter
@Setter
@NoArgsConstructor
public class PageResult<T extends Serializable> implements Serializable {
    /**
     * 总行数
     */
    private Long totalRows;
    /**
     * 总页数
     */
    private Long totalPage;
    /**
     * 当前页码
     */
    private Integer pageIndex;
    /**
     * 每页大小
     */
    private Integer pageSize;
    /**
     * 每页的数据
     */
    private List<T> rows;

    /**
     * 构造函数
     *
     * @param totalRows 总行数
     * @param pageIndex 当前页码
     * @param pageSize  每页大小
     * @param rows      每页的数据
     */
    public PageResult(Long totalRows, Integer pageIndex, Integer pageSize, List<T> rows) {
        this.totalRows = totalRows;
        totalPage = this.totalRows / pageSize;
        totalPage = this.totalRows % pageSize == 0 ? totalPage : totalPage + 1;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.rows = rows;
    }
}
